from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.edge.service import Service as EdgeService
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.action_chains import ActionChains
from actions import *
import time


def main():
    # 设置浏览器驱动路径
    edge_driver_path = "/home/huangxin/webdriver/msedgedriver"

    # 创建 Edge 服务对象
    edge_service = EdgeService(executable_path=edge_driver_path)

    # 创建 Edge 浏览器对象，传递服务对象
    driver = webdriver.Edge(service=edge_service)

    # 打开登录页面
    driver.get(LOGIN_URL)

    # 执行登录操作
    login(driver, USER_NAME, PASSWORD)
    time.sleep(3)
    cookies = driver.get_cookies()
    print(cookies)
    # 交易
    get_market_list(driver)

    time.sleep(3)
    cookies = driver.get_cookies()
    print(cookies)
    # 我的订单
    navigate_to_my_orders(driver)
    time.sleep(3)
    while True:
        navigate_to_my_purchases(driver)
        time.sleep(5)
        if has_order_data(driver):
            send_qq_email("麦特斯", "有订单")
            print("我的买入有订单")
        else:
            print("我的买入无订单")

        navigate_to_my_sales(driver)
        time.sleep(5)
        if has_order_data(driver):
            send_qq_email("麦特斯", "有订单")
            print("我的出售有订单")
        else:
            print("我的出售无订单")

    time.sleep(30)
    # 其他功能实现...

    # 关闭浏览器
    # driver.quit()


if __name__ == "__main__":
    main()
